package com.flyduck.mall.cms.h5.controller;

import cn.hutool.core.collection.ListUtil;
import com.flyduck.mall.cms.h5.service.H5CartItemService;
import com.flyduck.mall.cms.h5.vo.H5CartItemAddReqVO;
import com.flyduck.mall.cms.h5.vo.H5CartItemRespVO;
import com.flyduck.ss.common.core.domain.R;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @program: vueshop
 * @description:
 * @author: flyduck
 * @create: 2024-05-19 09:26
 **/
@RestController
@RequestMapping("/cart/h5/cartItem")
public class H5CartItemController {

    @Resource
    private H5CartItemService h5CartItemService;

    //@Login
    @GetMapping("/getCartItemList")
    public R<List<H5CartItemRespVO>> getCartItemList(){
        List<H5CartItemRespVO> cartItemResponseList = h5CartItemService.getCartItemList();
        return R.ok(cartItemResponseList);
    }

    //@Login
    @GetMapping("/getTotalCount")
    public R<Long> getTotalCount(){
        Long count = h5CartItemService.getTotalCount();
        return R.ok(count);
    }

    //@Login
    @PostMapping("/getTotalAmountByIds")
    public R<BigDecimal> getTotalAmountByIds(@RequestBody Long[] ids){
        BigDecimal totalAmount = h5CartItemService.getTotalAmountByIds(ListUtil.toList(ids));
        return R.ok(totalAmount);
    }

    //@Login
    @PostMapping("/updateQuantityById")
    public R<Void> updateQuantity(Long id, Integer quantity){
        h5CartItemService.updateQuantityById(id,quantity);
        return R.ok();
    }

    //@Login
    @PostMapping("addCartItem")
    public R<Void> addCartItem(@Validated @RequestBody H5CartItemAddReqVO h5CartItemAddReqVO){
        h5CartItemService.addCartItem(h5CartItemAddReqVO);
        return R.ok();
    }

    //@Login
    @PostMapping("batchDeleteByIds")
    public R<Void> batchDeleteByIds(@RequestBody Long[] ids){
        h5CartItemService.batchDeleteByIds(ids);
        return R.ok();
    }
}
